package zisu.netty.practice.netty.secs;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import zisu.netty.practice.netty.inBoundAndOutBound.MyByteToLongDecoder2;
import zisu.netty.practice.netty.inBoundAndOutBound.MyLongToByteEncoder;

/**
 * @Desc: ""
 * @Author: caixiang
 * @DATE: 2020/7/28 16:32
 */
public class MyServerInitializer extends ChannelInitializer<SocketChannel> {
    /**
     * [FF FF|00 00|00 01|00 00 00 01]
     * [FF FF|00 00|00 02|00 00 00 01]
     *
     * FF FF 00 00 00 05 00 00 00 03
     * FF FF 00 00 00 06 00 00 00 03
     * */

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        //入栈的 handler 进行解码 MyByteToLongDecoder
        //因为是 server ==>  client,也因为MyServerHandler 是后面那个addLast 所以先调用MyByteToLongDecoder 再调用MyServerHandler
        //pipeline.addLast(new MyByteToLongDecoder());
        pipeline.addLast(new MyByteToLongDecoder2());
        pipeline.addLast(new MyMessageToByteEncoder());
        //自定义handler 是业务处理逻辑
        pipeline.addLast(new MyServerHandler());
    }
}
